<template>
  <div class="home-container">
    <div class="banner-container">
      <img :src="require('../assets/home/banner.png')" alt="" />
    </div>
    <div class="theme-container">
      <div v-if="!isLogin">中国移动用户使用积分即可兑换</div>
      <div v-else>
        尊敬的用户，您当前积分为：<span>{{ score }}</span>
      </div>
    </div>
    <div class="middle-container">
      <div class="card-container">
        <div
          class="card-item"
          :class="[cardSelectIndex === index ? 'card-item-active' : '']"
          v-for="(item, index) in cardArr"
          :key="index"
          @click="cardClick(index)"
        >
          <div class="card-title">兑湘疆商城{{ item.shopScore }}积分</div>
          <div class="card-score">{{ item.mobileScore }}移动积分</div>
        </div>
      </div>
      <div>
        <Button v-if="!isLogin" title="立即兑换" @btnClick="btnLogin" />
        <Button v-else title="确认兑换" @btnClick="btnConfirm" />
      </div>
      <div class="explain-container">
        <div class="title-box">
          <img :src="require('../assets/home/tip_left.png')" alt="" />
          <div>活动说明</div>
          <div>{{ $store.state.age }}</div>
          <div>{{ $store.getters.myAge }}</div>
          <img :src="require('../assets/home/tip_right.png')" alt="" />
        </div>
        <div class="explain-content">
          <p>
            1、本次活动将采用一次性兑换形式，现对应的积分只能选择相对应的积分档位。
          </p>
          <p>
            2、积分可兑换相应档位奖励，奖励不可换为货币用，如果有以上行为，将进行追责。
          </p>
          <p>3、本活动的一切解释权归。</p>
        </div>
      </div>
    </div>
    <StepMask :showMask="showMask" @closeMask="showMask = false" />
  </div>
</template>

<script>
import Button from "../components/Button.vue";
import StepMask from "../components/StepMask.vue";
export default {
  name: "Home",
  components: {
    Button,
    StepMask,
  },
  data() {
    return {
      isLogin: false,
      score: 8312,
      cardSelectIndex: 1,
      cardArr: [
        {
          shopScore: 100,
          mobileScore: 15000,
        },
        {
          shopScore: 150,
          mobileScore: 20000,
        },
        {
          shopScore: 200,
          mobileScore: 25000,
        },
        {
          shopScore: 50,
          mobileScore: 13000,
        },
      ],
      showMask: false,
    };
  },
  created(){
    console.log(this.$router)
    console.log(this.$route)
  },
  methods: {
    cardClick(index) {
      // console.log(this.$store.state.age)
      // this.$store.state.age++
      console.log(this.$store);
      this.$store.commit("syncChange", 100);
      this.$store.dispatch("asyncChange", 200);

      if (this.cardSelectIndex == index) return;
      this.cardSelectIndex = index;
      let path;
      if (index % 2 === 0) {
        path = "/result";
      } else {
        path = "/other";
      }
      this.$router.push({
        path,
      });
    },
    btnLogin() {
      this.isLogin = true;
    },
    btnConfirm() {
      this.showMask = true;
    },
  },
};
</script>
<style lang="scss" scoped>
.home-container {
  width: 100%;
  min-height: 100%;
  background-color: #f8f9fa;
  .banner-container {
    width: 100%;
    img {
      width: 100%;
      display: block;
    }
  }
  .theme-container {
    padding: 0 15px;
    height: 50px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    font-size: 14px;
    background-color: #fff;
    color: #333;
    span {
      font-size: 15px;
      font-weight: bold;
      color: #fe5949;
    }
  }
  .middle-container {
    width: 100%;
    padding: 15px;
    box-sizing: border-box;
    .card-container {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
      margin-bottom: 35px;
      .card-item {
        margin-bottom: 10px;
        background-color: #fff;
        width: 47%;
        padding: 15px 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        border-radius: 5px;
        border: 1px solid transparent;
        box-shadow: 5px 5px 5px 5px #eee;
        &.card-item-active {
          border: 1px solid #ff7700;
          .card-title {
            color: #ff7700;
          }
          .card-score {
            color: #ff7700;
          }
        }
        .card-title {
          color: #333;
          font-size: 15px;
          line-height: 22px;
        }
        .card-score {
          color: #999;
          font-size: 12px;
        }
      }
    }
    .explain-container {
      margin-top: 45px;
      margin-bottom: 45px;
      width: 100%;
      padding: 10px 20px;
      box-sizing: border-box;
      background-color: #fff;
      border-radius: 5px;
      .title-box {
        display: flex;
        justify-content: center;
        align-items: center;
        img {
          width: 27px;
        }
        div {
          color: #333;
          font-size: 16px;
          margin: 0 10px;
        }
      }
      .explain-content {
        margin-top: 15px;
        margin-bottom: 20px;
        p {
          line-height: 25px;
          color: #333;
          font-size: 14px;
        }
      }
    }
  }
}
</style>
